package sg.edu.nus.iss.jass.privilege;

import sg.edu.nus.iss.jass.datastore.BaseDTO;
import sg.edu.nus.iss.jass.util.Util;

public class User extends BaseDTO {

	private Role role;
	private String roleId;
	private String username;
	private String password;

	/**
	 * Returns the role of the user which defines the level of privilege given
	 * to the user
	 * @return the role of the user
	 */
	public Role getRole() {
		return role;
	}
	
	/**
	 * Setting the role correctly after the authentication completes
	 * @param role
	 */
	public void setRole(Role role) {
		this.role = role;
	}

	public String getUsername() {
		return username;
	}
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getRoleId() {
		if(role != null){
			return role.getId();
		}
		if(!Util.isEmpty(roleId)) {
			return roleId;
		}
		return null;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	/** 
	 * Constructor for the User object
	 * @param role the role of the user
	 * @param username the username of the user
	 * @param password the password for the user
	 */
	public User(String username, String password, Role role) {
		this.username = username;
		this.password = password;
		this.role = role;
	}
	
	public User(String username, String password) {
		this.username = username;
		this.password = password;
		this.role = role;
	}
	
	public User() {}

}